


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > LauncherSmokeTest</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman</a>
</div>

<h1>Coverage Summary for Class: LauncherSmokeTest (nl.tudelft.jpacman)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">LauncherSmokeTest</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (5/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (33/33)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman;
&nbsp;
&nbsp;import static org.assertj.core.api.Assertions.assertThat;
&nbsp;
&nbsp;import nl.tudelft.jpacman.board.Direction;
&nbsp;import nl.tudelft.jpacman.game.Game;
&nbsp;import nl.tudelft.jpacman.level.Player;
&nbsp;import org.junit.jupiter.api.AfterEach;
&nbsp;import org.junit.jupiter.api.BeforeEach;
&nbsp;import org.junit.jupiter.api.Test;
&nbsp;
&nbsp;/**
&nbsp; * Smoke test launching the full game,
&nbsp; * and attempting to make a number of typical moves.
&nbsp; *
&nbsp; * This is &lt;strong&gt;not&lt;/strong&gt; a &lt;em&gt;unit&lt;/em&gt; test -- it is an end-to-end test
&nbsp; * trying to execute a large portion of the system&#39;s behavior directly from the
&nbsp; * user interface. It uses the actual sprites and monster AI, and hence
&nbsp; * has little control over what is happening in the game.
&nbsp; *
&nbsp; * Because it is an end-to-end test, it is somewhat longer
&nbsp; * and has more assert statements than what would be good
&nbsp; * for a small and focused &lt;em&gt;unit&lt;/em&gt; test.
&nbsp; *
&nbsp; * @author Arie van Deursen, March 2014.
&nbsp; */
<b class="fc">&nbsp;public class LauncherSmokeTest {</b>
&nbsp;
&nbsp;    private Launcher launcher;
&nbsp;
&nbsp;    /**
&nbsp;     * Launch the user interface.
&nbsp;     */
&nbsp;    @BeforeEach
&nbsp;    void setUpPacman() {
<b class="fc">&nbsp;        launcher = new Launcher();</b>
<b class="fc">&nbsp;        launcher.launch();</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Quit the user interface when we&#39;re done.
&nbsp;     */
&nbsp;    @AfterEach
&nbsp;    void tearDown() {
<b class="fc">&nbsp;        launcher.dispose();</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Launch the game, and imitate what would happen in a typical game.
&nbsp;     * The test is only a smoke test, and not a focused small test.
&nbsp;     * Therefore it is OK that the method is a bit too long.
&nbsp;     *
&nbsp;     * @throws InterruptedException Since we&#39;re sleeping in this test.
&nbsp;     */
&nbsp;    @SuppressWarnings({&quot;magicnumber&quot;, &quot;methodlength&quot;, &quot;PMD.JUnitTestContainsTooManyAsserts&quot;})
&nbsp;    @Test
&nbsp;    void smokeTest() throws InterruptedException {
<b class="fc">&nbsp;        Game game = launcher.getGame();</b>
<b class="fc">&nbsp;        Player player = game.getPlayers().get(0);</b>
&nbsp;
&nbsp;        // start cleanly.
<b class="fc">&nbsp;        assertThat(game.isInProgress()).isFalse();</b>
<b class="fc">&nbsp;        game.start();</b>
<b class="fc">&nbsp;        assertThat(game.isInProgress()).isTrue();</b>
<b class="fc">&nbsp;        assertThat(player.getScore()).isZero();</b>
&nbsp;
&nbsp;        // get points
<b class="fc">&nbsp;        game.move(player, Direction.EAST);</b>
<b class="fc">&nbsp;        assertThat(player.getScore()).isEqualTo(10);</b>
&nbsp;
&nbsp;        // now moving back does not change the score
<b class="fc">&nbsp;        game.move(player, Direction.WEST);</b>
<b class="fc">&nbsp;        assertThat(player.getScore()).isEqualTo(10);</b>
&nbsp;
&nbsp;        // try to move as far as we can
<b class="fc">&nbsp;        move(game, Direction.EAST, 7);</b>
<b class="fc">&nbsp;        assertThat(player.getScore()).isEqualTo(60);</b>
&nbsp;
&nbsp;        // move towards the monsters
<b class="fc">&nbsp;        move(game, Direction.NORTH, 6);</b>
<b class="fc">&nbsp;        assertThat(player.getScore()).isEqualTo(120);</b>
&nbsp;
&nbsp;        // no more points to earn here.
<b class="fc">&nbsp;        move(game, Direction.WEST, 2);</b>
<b class="fc">&nbsp;        assertThat(player.getScore()).isEqualTo(130);</b>
&nbsp;
<b class="fc">&nbsp;        move(game, Direction.NORTH, 2);</b>
&nbsp;
&nbsp;        // Sleeping in tests is generally a bad idea.
&nbsp;        // Here we do it just to let the monsters move.
<b class="fc">&nbsp;        Thread.sleep(500L);</b>
&nbsp;
&nbsp;        // we&#39;re close to monsters, this will get us killed.
<b class="fc">&nbsp;        move(game, Direction.WEST, 10);</b>
<b class="fc">&nbsp;        move(game, Direction.EAST, 10);</b>
&nbsp;//        assertThat(player.isAlive()).isTrue();
&nbsp;
<b class="fc">&nbsp;        game.stop();</b>
<b class="fc">&nbsp;        assertThat(game.isInProgress()).isFalse();</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Make number of moves in given direction.
&nbsp;     *
&nbsp;     * @param game The game we&#39;re playing
&nbsp;     * @param dir The direction to be taken
&nbsp;     * @param numSteps The number of steps to take
&nbsp;     */
&nbsp;    public static void move(Game game, Direction dir, int numSteps) {
<b class="fc">&nbsp;        Player player = game.getPlayers().get(0);</b>
<b class="fc">&nbsp;        for (int i = 0; i &lt; numSteps; i++) {</b>
<b class="fc">&nbsp;            game.move(player, dir);</b>
&nbsp;        }
<b class="fc">&nbsp;    }</b>
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-11 19:46</div>
</div>
</body>
</html>
